package com.acwing.lc.part1;

import java.io.*;

/**
 * @author rkc
 * @date 2022/9/5 16:34
 */
public class LC7整数反转 {

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        writer.println(reverse(nextInt()));
        writer.flush();
    }

    public static int reverse(int x) {
        int ans = 0;
        while (x != 0) {
            if (ans > 0 && ans > (Integer.MAX_VALUE - x % 10) / 10) return 0;
            if (ans < 0 && ans < (Integer.MIN_VALUE - x % 10) / 10) return 0;
            ans = ans * 10 + x % 10;
            x /= 10;
        }
        return ans;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
